Imports System.Windows.Forms

Public Class dlgFindEmployee
    Public employeeID As String

    Private Sub btnFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFind.Click
        Dim ds As DataSet
        '        ds = db.getvalue("select EmployeeID,eFullName as 'FullName' from Employee where Employeeid like '%" & txtFindText.Text.Replace("'", "''") & "%'" _
        '       & " Or eFullName Like '%" & txtFindText.Text.Replace("'", "''") & "%'")
        ds = db.getvalue("select t.EmployeeID,eFullName as 'FullName',(select dep_name from Department where departmentid=t.edepartment) as Department from Employee t where t.Employeeid like '%" & txtFindText.Text.Replace("'", "''") & "%'" _
        & " Or t.eFullName Like '%" & txtFindText.Text.Replace("'", "''") & "%'")
        dgvResultEmployee.DataSource = ds.Tables(0)
        For i As Integer = 0 To dgvResultEmployee.Columns.Count - 1
            dgvResultEmployee.Columns(i).Name = dgvResultEmployee.Columns(i).HeaderText
        Next
        dgvResultEmployee.Columns(0).Width = 80
        dgvResultEmployee.Columns(1).Width = 180
        dgvResultEmployee.Columns(2).Width = 180

    End Sub


    Private Sub dgvResultEmployee_CellMouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles dgvResultEmployee.CellMouseDoubleClick
        If e.RowIndex >= 0 And e.ColumnIndex >= 0 Then
            employeeID = dgvResultEmployee.Item("EmployeeID", e.RowIndex).Value
            'dlgEmployee.EmployeeID = employeeID
            'dlgEmployee.setActionName("Update")
            'dlgEmployee.ShowDialog()
            Me.DialogResult = System.Windows.Forms.DialogResult.OK
            'Me.Close()
        End If
    End Sub



    Private Sub dlgFindEmployee_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        'Me.Dispose()
    End Sub

    Private Sub dlgFindEmployee_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'CanteenDataSet.Employee' table. You can move, or remove it, as needed.
        dgvResultEmployee.DataSource = Nothing
        dgvResultEmployee.AllowUserToAddRows = False
        dgvResultEmployee.AllowUserToDeleteRows = False
        dgvResultEmployee.EditMode = DataGridViewEditMode.EditProgrammatically

        'txtFindText.Text = "abc"
        txtFindText.Focus()


    End Sub


    Private Sub txtFindText_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtFindText.TextChanged
        Dim ds As DataSet
        ds = db.getvalue("select t.EmployeeID,eFullName as 'FullName',(select dep_name from Department where departmentid=t.edepartment) as Department from Employee t where t.Employeeid like '%" & txtFindText.Text.Replace("'", "''") & "%'" _
        & " Or t.eFullName Like '%" & txtFindText.Text.Replace("'", "''") & "%'")
        dgvResultEmployee.DataSource = ds.Tables(0)
        For i As Integer = 0 To dgvResultEmployee.Columns.Count - 1
            dgvResultEmployee.Columns(i).Name = dgvResultEmployee.Columns(i).HeaderText
        Next
        dgvResultEmployee.Columns(0).Width = 80
        dgvResultEmployee.Columns(1).Width = 180
        dgvResultEmployee.Columns(2).Width = 180
        txtFindText.Focus()
    End Sub


End Class
